home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / SAMPLES1.PAK / DBCLOCK.PRG < prev    next >
Text File  |  1995-07-18  |  12KB  |  392 lines

  1. *******************************************************************************
  2. *  PROGRAM:      DBClock.prg
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         12/93
  7. *
  8. *  UPDATED:      5/95
  9. *
  10. *  REVISION:     $Revision:   1.32  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This is a digital non-mdi clock that you can modify to your
  15. *                liking. It can run in the background while other
  16. *                Visual dBASE programs are running.
  17. *                This program uses the DBTimer VBX control to update the clock.
  18. *                You can modify the way this clock looks by selecting
  19. *                desired options from the options menu.
  20. *                You can modify the font, color, and time display.
  21. *                The size of the time characters will change as you resize
  22. *                the clock form, but the time display should always be
  23. *                centered in the form.
  24. *
  25. *                WARNING:
  26. *                   If something goes awry, the timer might continue
  27. *                   running, and the Visual dBASE Alert window will come up
  28. *                   with each clock tick.  This could cause problems.
  29. *
  30. *  PARAMETERS:   None
  31. *
  32. *  CALLS:        DBTimer.vbx   (time VBX control)
  33. *                Buttons.cc    (custom controls file)
  34. *
  35. *  USAGE:        Do DBClock
  36. *
  37. *******************************************************************************
  38. create session
  39. set talk off
  40. set ldCheck off
  41. set design off
  42.  
  43. set procedure to program(1) additive
  44. set procedure to &_dbwinhome.samples\Buttons.cc additive
  45. local f
  46. f = new ClockForm()
  47. f.open()
  48.  
  49. *******************************************************************************
  50. *******************************************************************************
  51. class ClockForm of Form
  52. *******************************************************************************
  53.  
  54.    this.top = 0
  55.    this.left = 65.38
  56.    this.height = 4.08
  57.    this.width = 11.22
  58.    this.mdi = .F.
  59.    this.minimize = .T.
  60.    this.text = "Clock"
  61.    this.sizeable = .T.
  62.    this.moveable = .T.
  63.    this.sysMenu = .T.
  64.    this.colorNormal = "bg+/n"
  65.  
  66.    define text timeText of this;
  67.       property;
  68.          text time(),;
  69.          alignment 4,;
  70.          colornormal "bg+/n",;
  71.          height 6.12,;
  72.          width 11.22,;
  73.          fontName "Sans Serif",;
  74.          fontBold .F.
  75.  
  76.    load dll dbtimer.vbx
  77.    define dbtimer timer of this;
  78.       property;
  79.          Width          4.62,;
  80.          Height          2.37,;
  81.          Top          300.06,;
  82.          Left         300.12,;
  83.          OnTimer {;form.timeText.text = form.GetTime()}
  84.    define sampleInfoButton dbClockInfoButton of this;
  85.       property;
  86.          Width        3.5,;
  87.          Height       1.2,;
  88.          Top          .1,;
  89.          Left         13.9;
  90.       custom;
  91.          sampleName "Dbclock.prg"
  92.  
  93.    this.TimeProperty = CLASS::TimeProperty
  94.    this.DefineMenu()
  95.  
  96.  
  97.    *******************************************************************************
  98.    procedure OnOpen
  99.    *******************************************************************************
  100.    private optionsRef
  101.  
  102.    public formatMenuChecked, colorNormalMenuChecked, fontNameMenuChecked,;
  103.       fontBoldMenuChecked, fontItalicMenuChecked
  104.  
  105.  
  106.    this.menuReleased = .F.             && -- Indicates that form has no menu
  107.    this.timeFormat = 0                 && -- Format of the time text
  108.    this.GetTime = Get24Time            && -- Function called to display the time.
  109.                                        && GetTime will be set to Get24Time or
  110.                                        && Get12Time depending on the format
  111.                                        && menu option selected.
  112.  
  113.    optionsRef = this.MainMenu.Options  && So don't have to access reference
  114.                                        && each time
  115.  
  116.    formatMenuChecked      = optionsRef.Formats.TwentyFourHrFormat
  117.    colorNormalMenuChecked = optionsRef.Colors.CyanColor
  118.    fontNameMenuChecked    = optionsRef.Fonts.SansSerifFont
  119.    fontBoldMenuChecked    = optionsRef.Bold.BoldOff
  120.    fontItalicMenuChecked  = optionsRef.Italic.ItalicOff
  121.    this.OnSize(.F.,this.width,this.height)  && initial sizing
  122.    this.timer.enabled     = .T.
  123.  
  124.  
  125.    *******************************************************************************
  126.    procedure OnClose
  127.  
  128.    * Release all public variables.  This will be unnecessary when they
  129.    * will be properties.
  130.    *******************************************************************************
  131.  
  132.    set design on
  133.    release formatMenuChecked,colorNormalMenuChecked,fontNameMenuChecked,;
  134.       fontBoldMenuChecked,fontItalicMenuChecked
  135.    close procedure program(1)
  136.  
  137.  
  138.    *******************************************************************************
  139.    procedure OnGotFocus
  140.    *******************************************************************************
  141.  
  142.    set design off
  143.  
  144.  
  145.    *******************************************************************************
  146.    procedure OnLostFocus
  147.    *******************************************************************************
  148.  
  149.    set design on
  150.  
  151.  
  152.    *******************************************************************************
  153.    procedure OnSize (nType, width, height)
  154.  
  155.    * Resize the text to the form.
  156.    *******************************************************************************
  157.    local timeText
  158.  
  159.    timeText = form.timeText
  160.    timeText.width = width
  161.    timeText.height = height
  162.    timeText.fontSize = (height + width)/2
  163.    form.dbClockInfoButton.left = width - form.dbClockInfoButton.width
  164.  
  165.  
  166.    *******************************************************************************
  167.    procedure TwelveHour
  168.  
  169.    * Set up the time display to use 12 hour representation.
  170.    *******************************************************************************
  171.  
  172.    if this.timeFormat <> 12
  173.       this.timeFormat = 12
  174.       this.GetTime = Get12Time
  175.    endif
  176.  
  177.  
  178.    ********************************************************************************
  179.    procedure TwentyFourHour
  180.  
  181.    * Set up the time display to use 24 hour representation
  182.    ********************************************************************************
  183.  
  184.    if this.timeFormat <> 24
  185.       this.timeFormat = 24
  186.       this.GetTime = Get24Time
  187.    endif
  188.  
  189.  
  190.    ****************************************************************************
  191.    procedure TimeProperty
  192.  
  193.    * check the current menu item, and uncheck the previously checked item
  194.    * in that group.  Set the corresponding property of the text control.
  195.    ****************************************************************************
  196.    private propRef, propName, timeText, menuVar, proc
  197.  
  198.    propName = this.parent.value
  199.    menuVar = propName + "MenuChecked"
  200.    &menuVar..checked = .F.         && Uncheck group's checked menu
  201.    this.Checked = .T.
  202.    &menuVar = this    && This is now the checked menu.
  203.    if propName <> "Format"         && Change a property of the text control
  204.       timeText = form.timeText
  205.       propRef = "timeText." + propName
  206.       &propRef = this.value
  207.    else                            && Change the format of the text
  208.       proc = "form." + this.procName
  209.       &proc()
  210.    endif
  211.  
  212.  
  213.    *******************************************************************************
  214.    procedure DefineMenu
  215.  
  216.    * Create a menu for the clock
  217.    *******************************************************************************
  218.  
  219.    define menu MainMenu of this
  220.  
  221.    define menu Options of this.MainMenu;
  222.       property;
  223.          text "&Options"
  224.  
  225.    define menu ExitMenu of this.MainMenu.Options;
  226.       property;
  227.          text "&Exit",;
  228.          onclick {;form.Close()}
  229.    define menu Separator1 of this.MainMenu.Options;
  230.       property;
  231.          separator .T.
  232.  
  233.    define menu Colors of this.MainMenu.Options ;
  234.       property;
  235.          text "&Colors";
  236.       custom;
  237.          value "ColorNormal"
  238.    define menu CyanColor of this.MainMenu.Options.Colors;
  239.       property;
  240.          text "&Cyan",;
  241.          onclick this.TimeProperty,;
  242.          checked .T.;
  243.       custom;
  244.          value "bg+/n"
  245.    define menu YellowColor of this.MainMenu.Options.Colors;
  246.       property;
  247.          text "&Yellow",;
  248.          OnClick this.timeProperty;
  249.       custom;
  250.          value "gr+/n"
  251.    define menu MagentaColor of this.MainMenu.Options.Colors;
  252.       property;
  253.          text "&Magenta",;
  254.          OnClick this.timeProperty;
  255.       custom;
  256.          value "rb+/n"
  257.    define menu RedColor of this.MainMenu.Options.Colors;
  258.       property;
  259.          text "&Red",;
  260.          onclick this.timeProperty;
  261.       custom;
  262.          value "r+/n"
  263.  
  264.    define menu Separator2 of this.MainMenu.Options;
  265.       property;
  266.          separator .T.
  267.    define menu Formats of this.MainMenu.Options;
  268.       property;
  269.          text "&Formats";
  270.       custom;
  271.          value "Format"
  272.    define menu TwentyFourHrFormat of this.MainMenu.Options.Formats;
  273.       property;
  274.          text "Twenty Four Hour",;
  275.          onclick this.TimeProperty,;
  276.          checked .T.;
  277.       custom;
  278.          procName "TwentyFourHour"
  279.    define menu TwelveHrFormat of this.MainMenu.Options.Formats;
  280.       property;
  281.          text "Twelve Hour",;
  282.          onclick this.TimeProperty;
  283.       custom;
  284.          procName "TwelveHour"
  285.  
  286.    define menu Separator3 of this.MainMenu.Options;
  287.       property;
  288.          separator .T.
  289.    define menu Fonts of this.MainMenu.Options;
  290.       property;
  291.          text "&Fonts";
  292.       custom;
  293.          value "FontName"
  294.    define menu ArialFont of this.MainMenu.Options.Fonts;
  295.       property;
  296.          text "&Arial",;
  297.          onclick this.timeProperty;
  298.       custom;
  299.          value "Arial"
  300.    define menu ScriptFont of this.MainMenu.Options.Fonts;
  301.       property;
  302.          text "&Script",;
  303.          onclick this.timeProperty;
  304.       custom;
  305.          value "Script"
  306.    define menu RomanFont of this.MainMenu.Options.Fonts;
  307.       property;
  308.          text "&Roman",;
  309.          onclick this.timeProperty;
  310.       custom;
  311.          value "Roman"
  312.    define menu SerifFont of this.MainMenu.Options.Fonts;
  313.       property;
  314.          text "S&erif",;
  315.          onclick this.timeProperty;
  316.       custom;
  317.          value "Serif"
  318.    define menu SansSerifFont of this.MainMenu.Options.Fonts;
  319.       property;
  320.          text "Sa&ns Serif",;
  321.          onclick this.timeProperty,;
  322.          checked .T.;
  323.       custom;
  324.          value "Sans Serif"
  325.    define menu Bold of this.MainMenu.Options;
  326.       property;
  327.          text "&Bold Fonts";
  328.       custom;
  329.          value "FontBold"
  330.    define menu BoldOff of this.MainMenu.Options.Bold;
  331.       property;
  332.          text "O&ff",;
  333.          onclick this.timeProperty,;
  334.          checked .T.;
  335.       custom;
  336.          value .F.
  337.    define menu BoldOn of this.MainMenu.Options.Bold;
  338.       property;
  339.          text "&On",;
  340.          onclick this.timeProperty;
  341.       custom;
  342.          value .T.
  343.    define menu Italic of this.MainMenu.Options;
  344.       property;
  345.          text "&Italic Fonts";
  346.       custom;
  347.          value "FontItalic"
  348.    define menu ItalicOff of this.MainMenu.Options.Italic;
  349.       property;
  350.          text "O&ff",;
  351.          onclick this.timeProperty,;
  352.          checked .T.;
  353.       custom;
  354.          value .F.
  355.    define menu ItalicOn of this.MainMenu.Options.Italic;
  356.       property;
  357.          text "&On",;
  358.          onclick this.timeProperty;
  359.       custom;
  360.          value .T.
  361.  
  362.  
  363. endclass
  364.  
  365.  
  366. *******************************************************************************
  367. function Get12Time
  368.  
  369. * Create the string representing 12 hour time representation
  370. *******************************************************************************
  371. local time, hours
  372.  
  373. time = time()
  374. hours = val(time)
  375. return ltrim(str(mod(hours-1,12)+1)) + ;
  376.          substr(time,3) + ;
  377.          iif(hours < 12," AM"," PM")
  378.  
  379.  
  380. *******************************************************************************
  381. function Get24Time
  382.  
  383. * Create the string representing 24 hour time representation
  384. *******************************************************************************
  385.  
  386. return time()       && Time in Visual dBASE is in 24 hour format by default
  387.                     && (create session in beginning)
  388.  
  389.  
  390.  
  391.  
  392.